package com.ruoyi.model.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.model.domain.vo.ModelTaskVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.model.domain.ModelTask;
import com.ruoyi.model.service.IModelTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模型任务Controller
 *
 * @author rww
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/model/task")
public class ModelTaskController extends BaseController
{
    @Autowired
    private IModelTaskService modelTaskService;

    /**
     * 查询模型任务列表
     */
    @PreAuthorize("@ss.hasPermi('model:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(ModelTask modelTask)
    {
        startPage();
        List<ModelTask> list = modelTaskService.selectModelTaskList(modelTask);
        return getDataTable(list);
    }

    /**
     * 导出模型任务列表
     */
    @PreAuthorize("@ss.hasPermi('model:task:export')")
    @Log(title = "模型任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ModelTask modelTask)
    {
        List<ModelTask> list = modelTaskService.selectModelTaskList(modelTask);
        ExcelUtil<ModelTask> util = new ExcelUtil<ModelTask>(ModelTask.class);
        util.exportExcel(response, list, "模型任务数据");
    }

    /**
     * 获取模型任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(modelTaskService.selectModelTaskVoById(id));
    }

    /**
     * 执行任务
     */
    @PreAuthorize("@ss.hasPermi('model:task:exec')")
    @GetMapping(value = "/exec/{id}")
    public AjaxResult execTask(@PathVariable("id") Long id)
    {
        return toAjax(modelTaskService.execModelTaskVoById(id));
    }

    /**
     * 新增模型任务
     */
    @PreAuthorize("@ss.hasPermi('model:task:add')")
    @Log(title = "模型任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ModelTaskVo modelTask)
    {
        return toAjax(modelTaskService.insertModelTaskVo(modelTask));
    }

    /**
     * 修改模型任务
     */
    @PreAuthorize("@ss.hasPermi('model:task:edit')")
    @Log(title = "模型任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ModelTaskVo modelTask)
    {
        return toAjax(modelTaskService.updateModelTaskVo(modelTask));
    }
    @PostMapping("/updateState")
    public AjaxResult updateState(@RequestBody ModelTask modelTask)
    {
        return toAjax(modelTaskService.updateModelTask(modelTask));
    }


    /**
     * 删除模型任务
     */
    @PreAuthorize("@ss.hasPermi('model:task:remove')")
    @Log(title = "模型任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(modelTaskService.deleteModelTaskByIds(ids));
    }
}
